package com.tronsis.distribution.activity.me.agent;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.lzy.imagepicker.ImagePicker;
import com.lzy.imagepicker.bean.ImageItem;
import com.lzy.imagepicker.ui.ImageAndVideoPreviewSeeActivity;
import com.lzy.imagepicker.ui.ImageGridActivity;
import com.tronsis.distribution.R;
import com.tronsis.distribution.bean.AskQuitBean;
import com.tronsis.distribution.bean.UploadFileBean;
import com.tronsis.distribution.biz.factory.FileBizFactory;
import com.tronsis.distribution.biz.factory.UpgradeBizFactory;
import com.tronsis.distribution.eventbus.EventMessage;
import com.tronsis.distribution.eventbus.EventTag;
import com.tronsis.distribution.http.Url;
import com.tronsis.distribution.util.CommonUtil;
import com.tronsis.distribution.util.GlideImageLoader;
import com.tronsis.distribution.util.StateUtil;
import com.tronsis.library.activity.ToolBarBaseActivity;
import com.tronsis.library.adapter.recyclerview.CommonAdapter;
import com.tronsis.library.adapter.recyclerview.base.ViewHolder;
import com.tronsis.library.http.UICallBack;
import com.tronsis.library.imageloader.ImageLoader;
import com.tronsis.library.util.StringUtil;
import com.tronsis.library.util.ToastUtil;
import com.tronsis.library.util.WindowUtil;
import com.tronsis.library.widget.ConfirmDialog;

import org.greenrobot.eventbus.EventBus;

import java.io.File;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.lzy.imagepicker.ImagePicker.REQUEST_CODE_PREVIEW;

/**
 * 注释掉二期新加的代理功能
 */
public class AgentExitProcessingDetailActivity extends ToolBarBaseActivity {
    private static final int REQUEST_CAMERA = 125;
    private static final int REQUEST_ALBUM = 126;
    @BindView(R.id.tv_exit_name)
    TextView mTvExitName;
    @BindView(R.id.ll_phone)
    LinearLayout mLlPhone;
    @BindView(R.id.tv_is_clear)
    TextView mTvIsClear;
    @BindView(R.id.ll_id)
    LinearLayout mLlId;
    @BindView(R.id.tv_clear_type)
    TextView mTvClearType;
    @BindView(R.id.ll_goods_info)
    LinearLayout mLlGoodsInfo;
    @BindView(R.id.ll_product_price)
    LinearLayout mLlProductPrice;
    @BindView(R.id.tv_product_price)
    TextView mTvProductPrice;
    @BindView(R.id.rv_user_upload)
    RecyclerView mRvUserUpload;
    @BindView(R.id.ll_pay_voucher)
    LinearLayout mLlPayVoucher;
    @BindView(R.id.btn_pass)
    Button mBtnPass;
    @BindView(R.id.ll_clear_type)
    LinearLayout mLlClearType;
    @BindView(R.id.btn_reject)
    Button mBtnReject;
    @BindView(R.id.btn_submit)
    Button mBtnSubmit;
    @BindView(R.id.tv_name)
    TextView mTvName;
    @BindView(R.id.tv_phone)
    TextView mTvPhone;
    @BindView(R.id.tv_address)
    TextView mTvAddress;
    @BindView(R.id.ll_receiver)
    LinearLayout mLlReceiver;
    @BindView(R.id.tv_image_tips)
    TextView mTvImageTips;
    @BindView(R.id.tv_profit)
    TextView mTvProfit;
    @BindView(R.id.tv_total_type)
    TextView mTvTotalType;
    @BindView(R.id.tv_pay_money)
    TextView mTvPayMoney;

    @BindView(R.id.tv_label_deal)
    TextView mTvLabelDeal;
    @BindView(R.id.tv_label_pay_image)
    TextView mTvLabelPayImage;
    @BindView(R.id.rv_pay_image)
    RecyclerView mRvPay;

    private AskQuitBean mAskQuitBean;
    private ImageItem mImageItem = new ImageItem();
    private ArrayList<ImageItem> mImageList = new ArrayList<>();
//    private ArrayList<ImageItem> mPayImageList = new ArrayList<>();
    private CommonAdapter<ImageItem> mPayImageAdapter;
//    private CommonAdapter<ImageItem> mPayAdapter;
    private boolean mShowDelete = false;
    private PopupWindow mImagePopupWindow;
    private boolean isPayBack;   //true 上级退还金额，false 下级上缴金额


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_agent_exit_processing_detail);
        ButterKnife.bind(this);
        setTitle(true, getString(R.string.exit_agent_detail));
        initImageRv();

        mAskQuitBean = (AskQuitBean) getIntent().getSerializableExtra("AskQuitBean");
        setView(mAskQuitBean);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == ImagePicker.RESULT_CODE_ITEMS && data != null) {
            List<ImageItem> imageItems = (List<ImageItem>) data.getSerializableExtra(ImagePicker.EXTRA_RESULT_ITEMS);
            if (imageItems != null && imageItems.size() > 0) {
                mImageList.remove(mImageItem);
                mImageList.addAll(imageItems);
                if (mImageList.size() < 3) {
                    mImageList.add(mImageItem);
                }
                mPayImageAdapter.notifyDataSetChanged();
            }
        }

    }

    private void setView(AskQuitBean askQuitBean) {
        if (askQuitBean == null) {
            return;
        }
        mTvExitName.setText(TextUtils.isEmpty(askQuitBean.getUserName()) ? "--" : askQuitBean.getUserName());
        boolean isClear = askQuitBean.isClear();
        String clearType = askQuitBean.getClearType();
        mTvIsClear.setText(isClear ? "是" : "否");
        mTvProfit.setText(getString(R.string.format_price, askQuitBean.getMoney()));
        if (isClear) {
            //是清理库存
//            mLlClearType.setVisibility(View.VISIBLE);
            mLlGoodsInfo.setVisibility(View.VISIBLE);
//            mLlProductPrice.setVisibility(View.VISIBLE);

//            mTvClearType.setText(StateUtil.getAgentExitClearType(mContext, clearType));
//            mTvProductPrice.setText(getString(R.string.format_price, askQuitBean.getStockPrice()));

            if (StringUtil.isEquals(clearType, StateUtil.AGENT_QUIT_TYPE_RETURN)) {
                mLlProductPrice.setVisibility(View.VISIBLE);
                mTvProductPrice.setText(getString(R.string.format_price, askQuitBean.getStockPrice()));
                //退还库存
//                mLlProductPrice.setVisibility(View.VISIBLE);
//                Double total;
//                BigDecimal goodPriceBd = new BigDecimal(Double.toString(askQuitBean.getStockPrice()));
//                BigDecimal profitMoneyBd = new BigDecimal(Double.toString(askQuitBean.getMoney()));
//                if (askQuitBean.getMoney() > askQuitBean.getStockPrice()) {
//                    total = profitMoneyBd.subtract(goodPriceBd).doubleValue();
//                    mTvTotalType.setText("上缴金额");
//                } else {
//                    total = goodPriceBd.subtract(profitMoneyBd).doubleValue();
//                    mTvTotalType.setText("退还金额");
//                }
//                mTvPayMoney.setText(getString(R.string.format_price, total));
            } else if (StringUtil.isEquals(clearType, StateUtil.AGENT_QUIT_TYPE_DELIVERY)) {
                //发货
//                mTvPayMoney.setText(getString(R.string.format_price, askQuitBean.getMoney()));
                mLlReceiver.setVisibility(View.VISIBLE);
                mLlProductPrice.setVisibility(View.GONE);
                AskQuitBean.ReceiverAddrBean receiverAddr = askQuitBean.getReceiverAddr();
                if (receiverAddr != null) {
                    mTvName.setText(receiverAddr.getName());
                    mTvPhone.setText(receiverAddr.getPhone());
                    mTvAddress.setText(CommonUtil.getRegionString(receiverAddr.getRegion()) + receiverAddr.getDetail());
                }

            }

        } else {
//            mTvPayMoney.setText(getString(R.string.format_price, askQuitBean.getMoney()));
            mLlClearType.setVisibility(View.GONE);
            mLlGoodsInfo.setVisibility(View.GONE);
            mLlProductPrice.setVisibility(View.GONE);
        }

//        if (askQuitBean.getPriceFid() != null) {
//            mTvLabelPayImage.setVisibility(View.VISIBLE);
//            mRvPay.setVisibility(View.VISIBLE);
//            mTvLabelDeal.setVisibility(View.VISIBLE);
//            mPayImageList.clear();
//            mPayImageList.addAll(CommonUtil.getSplitImage(askQuitBean.getPriceFid()));
//            mPayAdapter.notifyDataSetChanged();
//        } else {
//            mTvLabelPayImage.setVisibility(View.GONE);
//            mRvPay.setVisibility(View.GONE);
//        }

        //退代理状态 VERIFY(待审核), HANDLE(待处理), CONFIRM(待确认), FINISH(已完成), REJECT(未通过)
        String state = askQuitBean.getState();
        if (state != null) {
            switch (state) {
                case StateUtil.AGENT_EXIT_VERIFY:
                    mBtnPass.setVisibility(View.VISIBLE);
                    mBtnReject.setVisibility(View.VISIBLE);
                    mLlPayVoucher.setVisibility(View.GONE);
                    break;
                case StateUtil.AGENT_EXIT_HANDLE:
                    mBtnPass.setVisibility(View.GONE);
                    mBtnReject.setVisibility(View.GONE);
                    mBtnPass.setText("确认");
                    if (StringUtil.isEquals(clearType, StateUtil.AGENT_QUIT_TYPE_RETURN)) {
                        //退还库存
                        mLlPayVoucher.setVisibility(View.VISIBLE);
                        mBtnSubmit.setVisibility(View.VISIBLE);

                        if (askQuitBean.getStockFid() != null) {
                            mTvImageTips.setText("付款凭证：");
                            mBtnSubmit.setVisibility(View.GONE);
                            ArrayList<ImageItem> splitImage = CommonUtil.getSplitImage(askQuitBean.getStockFid());
                            mImageList.clear();
                            mImageList.addAll(splitImage);
                            mPayImageAdapter.notifyDataSetChanged();
                        }
                        //退还库存
//                        if (askQuitBean.getMoney() < askQuitBean.getStockPrice()) {
//                            isPayBack = true;
//                            mLlPayVoucher.setVisibility(View.VISIBLE);
//                            mBtnSubmit.setVisibility(View.VISIBLE);
//                            if (askQuitBean.getStockFid() != null) {
//                                mTvImageTips.setText("付款凭证：");
//                                mBtnSubmit.setVisibility(View.GONE);
//                                ArrayList<ImageItem> splitImage = CommonUtil.getSplitImage(askQuitBean.getStockFid());
//                                mImageList.clear();
//                                mImageList.addAll(splitImage);
//                                mPayImageAdapter.notifyDataSetChanged();
//                            } else {
//                                mTvImageTips.setText("*请上传付款凭证：");
//                            }
//                        } else if (askQuitBean.getMoney() == askQuitBean.getStockPrice()) {
//                            mBtnPass.setVisibility(View.GONE);
//                            mBtnReject.setVisibility(View.GONE);
//
//                        } else {
//                            //allen: 判断下级有没有上传上缴凭证，如果有，审核是否通过
//                            if (askQuitBean.getPriceFid() != null) {
//                                isPayBack = false;
//                                if (!askQuitBean.isConfirm()) {
//                                    mBtnPass.setVisibility(View.VISIBLE);
//                                    mBtnReject.setVisibility(View.VISIBLE);
//                                }
//                            }
//                        }
//                    } else {
//                        if (askQuitBean.getMoney() > 0) {//下级需要上缴金额
//                            //allen: 判断下级有没有上传上缴凭证，如果有，审核是否通过
//                            if (askQuitBean.getPriceFid() != null) {
//                                isPayBack = false;
//                                if (!askQuitBean.isConfirm()) {
//                                    mBtnPass.setVisibility(View.VISIBLE);
//                                    mBtnReject.setVisibility(View.VISIBLE);
//                                }
//                            }
//                        }
                    }


                    break;
                case StateUtil.AGENT_EXIT_FINISH:
                    mBtnPass.setVisibility(View.GONE);
                    mBtnReject.setVisibility(View.GONE);
                    mTvImageTips.setText("付款凭证：");
                    mTvImageTips.setTextColor(getResources().getColor(R.color.text_normal));
                    mLlPayVoucher.setVisibility(View.GONE);
                    if (askQuitBean.getStockFid() != null) {
                        mLlPayVoucher.setVisibility(View.VISIBLE);
                        mTvImageTips.setText("付款凭证：");
                        ArrayList<ImageItem> splitImage = CommonUtil.getSplitImage(askQuitBean.getStockFid());
                        mImageList.clear();
                        mImageList.addAll(splitImage);
                        mPayImageAdapter.notifyDataSetChanged();
                    }
                    break;
                case StateUtil.AGENT_EXIT_REJECT:
                default:
                    mBtnPass.setVisibility(View.GONE);
                    mBtnReject.setVisibility(View.GONE);
                    mLlPayVoucher.setVisibility(View.GONE);
                    break;
            }
        }
    }

    private void initImageRv() {
        mImageItem.path = "";
        mImageItem.addTime = System.currentTimeMillis();
        if (mImageList.size() < 3) {
            mImageList.add(mImageItem); // 插入 + 号占位数据
        }

        mPayImageAdapter = new CommonAdapter<ImageItem>(mContext, mImageList, R.layout.item_grid_image_view) {
            @Override
            protected void convert(final ViewHolder holder, final ImageItem imageItem, final int position) {
                ImageView ivItem = (ImageView) holder.getView(R.id.iv_item);
                holder.getView(R.id.iv_delete).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        showDeleteConfirmDialog(position);
                    }
                });

                ivItem.setOnLongClickListener(new View.OnLongClickListener() {
                    @Override
                    public boolean onLongClick(View v) {
                        if (StringUtil.isEquals(mAskQuitBean.getState(), StateUtil.AGENT_EXIT_HANDLE)) {
                            if (mShowDelete) {
                                mShowDelete = false;
                            } else {
                                mShowDelete = true;
                            }
                            notifyDataSetChanged();
                        }
                        return false;
                    }
                });

                ivItem.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (TextUtils.isEmpty(mImageList.get(position).path) && TextUtils.isEmpty(mImageList.get(position).url)) {
                            return;
                        }

                        mImageList.remove(mImageItem);

                        Intent intentPreview = new Intent(mContext, ImageAndVideoPreviewSeeActivity.class);
                        intentPreview.putExtra(ImagePicker.EXTRA_SELECTED_IMAGE_POSITION, position);
                        intentPreview.putParcelableArrayListExtra(ImagePicker.EXTRA_IMAGE_ITEMS, mImageList);
                        startActivityForResult(intentPreview, REQUEST_CODE_PREVIEW);
                    }
                });

                if (TextUtils.isEmpty(imageItem.path) && TextUtils.isEmpty(imageItem.url)) {
                    holder.getView(R.id.iv_delete).setVisibility(View.GONE);
                    ivItem.setImageResource(R.drawable.icon_add_res);

                    ivItem.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            showImagePopupWindow();
                        }
                    });

                } else {
                    if (TextUtils.isEmpty(imageItem.path)) {
                        ImageLoader.display(mContext, imageItem.url, ivItem);
                    }
                    if (TextUtils.isEmpty(imageItem.url)) {
                        ImageLoader.display(mContext, new File(imageItem.path), ivItem);
                    }

                    ivItem.setOnLongClickListener(new View.OnLongClickListener() {
                        @Override
                        public boolean onLongClick(View v) {
                            if (mAskQuitBean != null && StringUtil.isEquals(mAskQuitBean.getState(), StateUtil.AGENT_EXIT_HANDLE)) {
                                if (mShowDelete) {
                                    mShowDelete = false;
                                } else {
                                    mShowDelete = true;
                                }
                                notifyDataSetChanged();
                            }
                            return false;
                        }
                    });

                    ivItem.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if (TextUtils.isEmpty(mImageList.get(position).path) && TextUtils.isEmpty(mImageList.get(position).url)) {
                                return;
                            }

                            if (mImageList.contains(mImageItem)) {
                                mImageList.remove(mImageItem);
                            }

                            Intent intentPreview = new Intent(mContext, ImageAndVideoPreviewSeeActivity.class);
                            intentPreview.putExtra(ImagePicker.EXTRA_SELECTED_IMAGE_POSITION, position);
                            intentPreview.putParcelableArrayListExtra(ImagePicker.EXTRA_IMAGE_ITEMS, mImageList);
                            startActivityForResult(intentPreview, REQUEST_CODE_PREVIEW);
                        }
                    });

                    if (mShowDelete) {
                        holder.getView(R.id.iv_delete).setVisibility(View.VISIBLE);
                    } else {
                        holder.getView(R.id.iv_delete).setVisibility(View.GONE);
                    }
                }
            }


        };


        mRvUserUpload.setLayoutManager(new GridLayoutManager(mContext, 3, LinearLayoutManager.VERTICAL, false) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        });
        mRvUserUpload.setAdapter(mPayImageAdapter);
        mRvUserUpload.setHasFixedSize(true);
        mRvUserUpload.setNestedScrollingEnabled(false);

//        //Allen：下级上缴凭证
//        mPayAdapter = new CommonAdapter<ImageItem>(mContext, mPayImageList, R.layout.item_grid_image_view) {
//            @Override
//            protected void convert(final ViewHolder holder, final ImageItem imageItem, final int position) {
//                ImageView ivItem = holder.getView(R.id.iv_item);
//                if (TextUtils.isEmpty(imageItem.url)) {
//                    ImageLoader.display(mContext, new File(imageItem.path), ivItem);
//                }
//
//                if (TextUtils.isEmpty(imageItem.path)) {
//                    ImageLoader.display(mContext, imageItem.url, ivItem);
//                }
//
//                ivItem.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        if (TextUtils.isEmpty(mPayImageList.get(position).path) && TextUtils.isEmpty(mPayImageList.get(position).url)) {
//                            return;
//                        }
//                        Intent intentPreview = new Intent(mContext, ImageAndVideoPreviewSeeActivity.class);
//                        intentPreview.putExtra(ImagePicker.EXTRA_SELECTED_IMAGE_POSITION, position);
//                        intentPreview.putParcelableArrayListExtra(ImagePicker.EXTRA_IMAGE_ITEMS, mPayImageList);
//                        startActivityForResult(intentPreview, REQUEST_CODE_PREVIEW);
//                    }
//                });
//            }
//
//
//        };
//        mRvPay.setLayoutManager(new GridLayoutManager(mContext, 3, LinearLayoutManager.VERTICAL, false) {
//            @Override
//            public boolean canScrollVertically() {
//                return false;
//            }
//        });
//        mRvPay.setAdapter(mPayAdapter);
//        mRvPay.setHasFixedSize(true);
//        mRvPay.setNestedScrollingEnabled(false);
    }

    private void showImagePopupWindow() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_album_camera, null);
        // 强制隐藏键盘
        InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        if (mImagePopupWindow == null) {

            ImagePicker imagePicker = ImagePicker.getInstance();
            imagePicker.setImageLoader(new GlideImageLoader());
            imagePicker.setCrop(false);
            imagePicker.setMultiMode(true);
            imagePicker.setShowCamera(true);

            mImagePopupWindow = new PopupWindow(view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            mImagePopupWindow.setFocusable(true);
            mImagePopupWindow.setOutsideTouchable(true);
            /* mImagePopupWindow.setBackgroundDrawable(new BitmapDrawable());*/
            mImagePopupWindow.setAnimationStyle(R.style.AnimationBottomDialog);
            mImagePopupWindow.setTouchInterceptor(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View view, MotionEvent motionEvent) {
                    if (motionEvent.getAction() == MotionEvent.ACTION_OUTSIDE) {
                        mImagePopupWindow.dismiss();
                        return true;
                    }
                    return false;
                }
            });
            mImagePopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
                @Override
                public void onDismiss() {
                    WindowUtil.setPopWindowBackgroundAlpha(AgentExitProcessingDetailActivity.this, 1f);
                }
            });
            view.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    mImagePopupWindow.dismiss();
                }
            });
            view.findViewById(R.id.btn_camera).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    mImagePopupWindow.dismiss();
                    checkPermission(new CheckPermListener() {
                        @Override
                        public void superPermission() {
                            Intent intent = new Intent(mContext, ImageGridActivity.class);
                            intent.putExtra(ImageGridActivity.EXTRAS_TAKE_PICKERS, true);
                            intent.putExtra(ImageGridActivity.EXTRAS_IMAGES, (Serializable) mImageList);
                            startActivityForResult(intent, REQUEST_CAMERA);
                            mImagePopupWindow.dismiss();
                        }
                    }, R.string.ask_again, Manifest.permission.CAMERA);
                }
            });
            view.findViewById(R.id.btn_album).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    mImagePopupWindow.dismiss();
                    checkPermission(new CheckPermListener() {
                        @Override
                        public void superPermission() {
                            ImagePicker.getInstance().setSelectLimit(4 - mImageList.size());
                            Intent intent = new Intent(mContext, ImageGridActivity.class);
                            intent.putExtra(ImageGridActivity.EXTRAS_TAKE_PICKERS, false);
                            startActivityForResult(intent, REQUEST_ALBUM);
                            mImagePopupWindow.dismiss();
                        }
                    }, R.string.ask_again, Manifest.permission.READ_EXTERNAL_STORAGE);
                }
            });
        }
        WindowUtil.setPopWindowBackgroundAlpha(this, 0.7f);
        mImagePopupWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0);
    }

    private void showDeleteConfirmDialog(final int position) {
        ConfirmDialog mConfirmDialog = new ConfirmDialog(mContext, new ConfirmDialog.OnBottomButtonClickListener() {
            @Override
            public void onLeftButtonClick(View view) {
            }

            @Override
            public void onRightButtonClick(View view) {
                mImageList.remove(position);
                if (!mImageList.contains(mImageItem)) {
                    mImageList.add(mImageItem);
                }
                mPayImageAdapter.notifyDataSetChanged();
            }

        });
        mConfirmDialog.showDialog("确认删除？", "取消", "确认");
    }


    @OnClick(R.id.ll_goods_info)
    void goodsInfoClick() {
        Intent intent = new Intent(mContext, AgentExitGoodsActivity.class);
        intent.putExtra("quitId", mAskQuitBean.getId());
        startActivity(intent);
    }


    @OnClick(R.id.btn_pass)
    void passClick() {
        httpPass();
//        if (isPayBack || mAskQuitBean.getMoney() == mAskQuitBean.getStockPrice() || StateUtil.AGENT_EXIT_VERIFY.equals(mAskQuitBean.getState())) {
//            httpPass();
//        } else {
//            confirmFid();
//        }

    }

    @OnClick(R.id.btn_reject)
    void rejectClick() {
        httpReject();
//        if (isPayBack || mAskQuitBean.getMoney() == mAskQuitBean.getStockPrice() || StateUtil.AGENT_EXIT_VERIFY.equals(mAskQuitBean.getState())) {
//            httpReject();
//        } else {
//            confirmFail();
//        }

    }

    @OnClick(R.id.btn_submit)
    void submitClick() {
        if (mImageList.contains(mImageItem) && mImageList.size() == 1) {
            ToastUtil.showMessage(this, "请添加付款凭证");
            return;
        }

        httpCommitUploadFile(mImageList);
    }

    private void httpCommitUploadFile(ArrayList<ImageItem> customImageList) {
        final ArrayList<File> fileList = new ArrayList<>();


        for (ImageItem imageItem : customImageList) {
            if (!TextUtils.isEmpty(imageItem.path)) {
                fileList.add(new File(imageItem.path));
            }
        }
        try {
            FileBizFactory.createBiz().uploads(this, fileList, Url.FILE_TYPE_IMAGE, new UICallBack() {
                @Override
                public void onStart() {
                    showLoadingDialog();
                }

                @Override
                public void onRefresh(Object data) {
                    List<UploadFileBean> fileBeanList = (List<UploadFileBean>) data;
                    List<String> fileIds = new ArrayList<>();
                    for (UploadFileBean uploadFileBean : fileBeanList) {
                        fileIds.add(uploadFileBean.getId());
                    }

                    String ids = StringUtil.arrayList(fileIds);

                    httpSubmit(ids);
                }

                @Override
                public void onFailure(int status) {
                    dismissLoadingDialog();
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
            dismissLoadingDialog();
        }

    }

    private void httpSubmit(String fid) {
        try {
            UpgradeBizFactory.createBiz().askQuitPay(this, mAskQuitBean.getId(), fid, new UICallBack() {
                @Override
                public void onStart() {

                }

                @Override
                public void onRefresh(Object data) {
                    ToastUtil.showMessage(mContext, "提交成功");
                    EventBus.getDefault().post(new EventMessage(EventTag.EXIT_AGENT_LIST, mAskQuitBean.getState()));
                    dismissLoadingDialog();
                    finish();
                }

                @Override
                public void onFailure(int status) {
                    dismissLoadingDialog();
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
            dismissLoadingDialog();
        }

    }


    private void httpPass() {
        try {
            UpgradeBizFactory.createBiz().askQuitPass(this, mAskQuitBean.getId(), new UICallBack() {
                @Override
                public void onStart() {
                    showLoadingDialog();
                }

                @Override
                public void onRefresh(Object data) {
                    ToastUtil.showMessage(mContext, "已通过");
                    EventBus.getDefault().post(new EventMessage(EventTag.EXIT_AGENT_LIST, mAskQuitBean.getState()));
                    dismissLoadingDialog();
                    finish();
                }

                @Override
                public void onFailure(int status) {
                    dismissLoadingDialog();
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
            dismissLoadingDialog();
        }
    }

    private void httpReject() {
        try {
            UpgradeBizFactory.createBiz().askQuitReject(this, mAskQuitBean.getId(), new UICallBack() {
                @Override
                public void onStart() {
                    showLoadingDialog();
                }

                @Override
                public void onRefresh(Object data) {
                    ToastUtil.showMessage(mContext, "已拒绝");
                    EventBus.getDefault().post(new EventMessage(EventTag.EXIT_AGENT_LIST, mAskQuitBean.getState()));
                    dismissLoadingDialog();
                    finish();
                }

                @Override
                public void onFailure(int status) {
                    dismissLoadingDialog();
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
            dismissLoadingDialog();
        }
    }

    /**
     * allen: 上级确认通过上缴金额凭证
     */
    private void confirmFid() {
        try {
            UpgradeBizFactory.createBiz().confirmFid(this, mAskQuitBean.getId(), new UICallBack() {
                @Override
                public void onStart() {
                    showLoadingDialog();
                }

                @Override
                public void onRefresh(Object data) {
                    ToastUtil.showMessage(mContext, "已通过");
                    EventBus.getDefault().post(new EventMessage(EventTag.EXIT_AGENT_LIST, mAskQuitBean.getState()));
                    dismissLoadingDialog();
                    finish();
                }

                @Override
                public void onFailure(int status) {
                    dismissLoadingDialog();
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
            dismissLoadingDialog();
        }
    }

    /**
     * allen: 上级确认不通过上缴金额凭证
     */
    private void confirmFail() {
        try {
            UpgradeBizFactory.createBiz().confirmFail(this, mAskQuitBean.getId(), new UICallBack() {
                @Override
                public void onStart() {
                    showLoadingDialog();
                }

                @Override
                public void onRefresh(Object data) {
                    ToastUtil.showMessage(mContext, "已拒绝");
                    EventBus.getDefault().post(new EventMessage(EventTag.EXIT_AGENT_LIST, mAskQuitBean.getState()));
                    dismissLoadingDialog();
                    finish();
                }

                @Override
                public void onFailure(int status) {
                    dismissLoadingDialog();
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
            dismissLoadingDialog();
        }
    }

}
